package com.qf.service.impl;

import com.qf.domain.Account;
import com.qf.mapper.AccountMapper;
import com.qf.service.AccountService;

public class AccountServiceImpl implements AccountService {
    private AccountMapper mapper;
    public void setMapper(AccountMapper mapper){
        this.mapper = mapper;
    }
    @Override
    public void transfer(String fromName, String toName, double money) {
        //根据账户名查找账户
        Account fromAccount=mapper.findByName(fromName);
        Account toAccount = mapper.findByName(toName);
        //更改余额
        fromAccount.setMoney(fromAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney()+money);
        //更新到数据库
        mapper.update(fromAccount);
        mapper.update(toAccount);
    }
}
